/* LogWriter.java
 * 
 * Alfred Olschnoegger
 * 30.06.2008
 */

package exceptions;

import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.FileWriter;
import java.io.OutputStream;
import java.io.PrintStream;

/**
 * TODO description
 *
 * @date 30.06.2008
 * @author Alfred Olschnoegger
 */

public class LogWriter {
	
	public void write(Exception e) {
		try {
			// Create file
			FileWriter fstream = new FileWriter("log.txt");
			BufferedWriter out = new BufferedWriter(fstream);
			out.append(getStackTrace(e));
			// Close the output stream
			out.close();
		} catch (Exception ex) {// Catch exception if any
			ex.printStackTrace();
		}
	}
	
	private String getStackTrace(Exception x) {
		OutputStream buf = new ByteArrayOutputStream();
		PrintStream p = new PrintStream(buf);
		x.printStackTrace(p);
		return buf.toString();
	}
}


// end of LogWriter.java
